/*
 * This file is part of MultiplyRSSGenerator.
 * 
 * MultiplyRSSGenerator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author Hidayat Febiansyah
 * @email havban@gmail.com
 * @link http://code.google.com/p/multiply-rss-generator/
 * @year 2012
 */
package febi.rssgen.com.multiply.gui;

import febi.com.util.TextAreaOutputStream;
import febi.rssgen.com.rss.Global;
import febi.rssgen.multiply.MultiplyRSSGeneratorHandler;
import java.io.File;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.prefs.Preferences;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.text.DefaultCaret;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author itrc169
 */
public class MainFrame extends javax.swing.JFrame implements TaskViewer {

    JFileChooser fc;
    private Preferences prefs;
    AboutFrame aboutFrame;
    ArrayList<TaskItem> taskList;
    
    SimpleDateFormat dtFmt = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();

        initFields();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rdo_group_date = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txt_user = new javax.swing.JTextField();
        chk_journal = new javax.swing.JCheckBox();
        chk_reviews = new javax.swing.JCheckBox();
        chk_recipes = new javax.swing.JCheckBox();
        chk_notes = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_outputFolder = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        btn_process = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt_output = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        txt_notification = new javax.swing.JTextArea();
        lbl_version = new javax.swing.JLabel();
        chk_photos = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        dt_start = new com.michaelbaranov.microba.calendar.DatePicker();
        jLabel8 = new javax.swing.JLabel();
        dt_end = new com.michaelbaranov.microba.calendar.DatePicker();
        radio_allDate = new javax.swing.JRadioButton();
        radio_rangedDate = new javax.swing.JRadioButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel1.setText("Multiply Username / Address   *ex. havban or havban.multiply.com");

        jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel2.setText("Folder");

        chk_journal.setText("Journal");

        chk_reviews.setText("Reviews");

        chk_recipes.setText("Recipes");

        chk_notes.setText("Notes");

        jLabel4.setFont(jLabel4.getFont().deriveFont(jLabel4.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel4.setText("Output");

        jLabel5.setFont(jLabel5.getFont().deriveFont(jLabel5.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel5.setText("Save to Folder");

        jButton1.setText("Browse");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        btn_process.setText("Process");
        btn_process.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_processActionPerformed(evt);
            }
        });

        jScrollPane1.setAutoscrolls(true);

        txt_output.setColumns(20);
        txt_output.setRows(5);
        jScrollPane1.setViewportView(txt_output);

        jScrollPane2.setAutoscrolls(true);

        txt_notification.setColumns(20);
        txt_notification.setRows(5);
        jScrollPane2.setViewportView(txt_notification);

        lbl_version.setText("Version: 0.0");

        chk_photos.setText("Photos");

        jLabel6.setFont(jLabel6.getFont().deriveFont(jLabel6.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel6.setText("Date Range");

        jLabel8.setText("to");

        radio_allDate.setText("ALL");
        radio_allDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_allDateActionPerformed(evt);
            }
        });

        radio_rangedDate.setText("Ranged");
        radio_rangedDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_rangedDateActionPerformed(evt);
            }
        });

        jMenu1.setText("RSSGen");

        jMenuItem1.setText("About");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem3.setText("Update");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setText("Exit");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(chk_journal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chk_reviews)
                        .addGap(18, 18, 18)
                        .addComponent(chk_recipes))
                    .addComponent(jLabel6)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(radio_allDate)
                                .addGap(18, 18, 18)
                                .addComponent(radio_rangedDate)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(148, 148, 148)
                                .addComponent(chk_notes)
                                .addGap(18, 18, 18)
                                .addComponent(chk_photos))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(dt_start, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(7, 7, 7)
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(dt_end, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btn_process, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txt_outputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txt_user, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_version)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_version))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chk_journal)
                            .addComponent(chk_reviews)
                            .addComponent(chk_recipes)
                            .addComponent(chk_notes)
                            .addComponent(chk_photos))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(radio_allDate)
                                        .addComponent(radio_rangedDate))
                                    .addComponent(dt_start, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel8)
                            .addComponent(dt_end, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_outputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btn_process)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 4, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_processActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_processActionPerformed

        saveFields();

        taskList = new ArrayList();

        if (chk_journal.isSelected()) {
            taskList.add(new TaskItem("Journal", "", this));
        }
        if (chk_reviews.isSelected()) {
            taskList.add(new TaskItem("Reviews", "", this));
        }
        if (chk_recipes.isSelected()) {
            taskList.add(new TaskItem("Recipes", "", this));
        }
        if (chk_notes.isSelected()) {
            taskList.add(new TaskItem("Notes", "", this));
        }
        if (chk_photos.isSelected()) {
            taskList.add(new TaskItem("Photos", "", this));
        }

        taskList.add(new TaskItem("Summary", "", this));
        
        Date startDate=null, endDate=null;
        if(radio_rangedDate.isSelected()){
            startDate = dt_start.getDate();
            endDate = dt_end.getDate();
        }

        MultiplyRSSGeneratorHandler.startProcess(
                txt_user.getText().trim(),
                chk_journal.isSelected(),
                chk_reviews.isSelected(),
                chk_recipes.isSelected(),
                chk_notes.isSelected(),
                chk_photos.isSelected(),
                txt_outputFolder.getText(),
                startDate,
                endDate,
                new JComponent[]{btn_process},
                null,
                this,
                this);

    }//GEN-LAST:event_btn_processActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        if (txt_outputFolder.getText().length() > 0) {
            fc.setCurrentDirectory(new File(txt_outputFolder.getText()).getParentFile());
        }
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int rVal = fc.showOpenDialog(this);
        if (rVal == JFileChooser.APPROVE_OPTION) {
            txt_outputFolder.setText(fc.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        aboutFrame = new AboutFrame();
        aboutFrame.showMe(this);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        JOptionPane.showMessageDialog(this, "Not yet implemented");
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void radio_rangedDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_rangedDateActionPerformed
        setDateRangeActive(radio_rangedDate.isSelected());
    }//GEN-LAST:event_radio_rangedDateActionPerformed

    private void radio_allDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_allDateActionPerformed
        setDateRangeActive(!radio_allDate.isSelected());
    }//GEN-LAST:event_radio_allDateActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_process;
    private javax.swing.JCheckBox chk_journal;
    private javax.swing.JCheckBox chk_notes;
    private javax.swing.JCheckBox chk_photos;
    private javax.swing.JCheckBox chk_recipes;
    private javax.swing.JCheckBox chk_reviews;
    private com.michaelbaranov.microba.calendar.DatePicker dt_end;
    private com.michaelbaranov.microba.calendar.DatePicker dt_start;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbl_version;
    private javax.swing.JRadioButton radio_allDate;
    private javax.swing.JRadioButton radio_rangedDate;
    private javax.swing.ButtonGroup rdo_group_date;
    private javax.swing.JTextArea txt_notification;
    private javax.swing.JTextArea txt_output;
    private javax.swing.JTextField txt_outputFolder;
    private javax.swing.JTextField txt_user;
    // End of variables declaration//GEN-END:variables

    private void initFields() {
        fc = new JFileChooser();

        prefs = Preferences.userRoot().node(this.getClass().getName());

        //textboxesI
        txt_user.setText(prefs.get("MultiplyRSSGenerator::txt_user", ""));
        txt_outputFolder.setText(prefs.get("MultiplyRSSGenerator::txt_outputFolder", ""));

        //capturing process output
        System.setOut(new PrintStream(new TextAreaOutputStream(txt_output)));
        System.setErr(new PrintStream(new TextAreaOutputStream(txt_output)));

        //check all
        chk_journal.setSelected(true);
        chk_notes.setSelected(true);
        chk_recipes.setSelected(true);
        chk_reviews.setSelected(true);
        chk_photos.setSelected(true);

        //set version label
        lbl_version.setText("Version: " + Global.VERSION);

        DefaultCaret caret = (DefaultCaret) txt_output.getCaret();
        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
        
        //dates
        rdo_group_date.add(radio_allDate);
        rdo_group_date.add(radio_rangedDate);
        radio_allDate.setSelected(true);
        setDateRangeActive(false);
        
        dt_start.setDateFormat(dtFmt);
        dt_end.setDateFormat(dtFmt);
        
    }

    private void saveFields() {
        //textboxes
        prefs.put("MultiplyRSSGenerator::txt_user", txt_user.getText());
        prefs.put("MultiplyRSSGenerator::txt_outputFolder", txt_outputFolder.getText());
    }

    @Override
    public void updateStatus(TaskItem item) {

        String message = "";
        int taskStatus = item.getStatus();

        //append the txt_notification
        if (taskStatus == TaskItem.ONGOING) {
            message += item.getName() + ": " + item.getDesc();
        } else {
            if (taskStatus == TaskItem.ERROR) {
                message += "[ERROR] " + item.getName() + " failed to process\n"
                        + "-- Message: " + item.getDesc();
            } else {
                message += "[DONE] " + item.getName() + " successfully processed";
            }
        }

        txt_notification.append(message + "\n");
    }

    @Override
    public ArrayList<TaskItem> getTaskList() {
        return this.taskList;
    }

    @Override
    public TaskItem getTaskByName(String name) {
        TaskItem foundItem = null;

        for (TaskItem item : taskList) {
            if (item.getName().toLowerCase().equals(name.toLowerCase())) {
                foundItem = item;
                break;
            }
        }

        return foundItem;
    }
    
    private void setDateRangeActive(boolean b){
        dt_start.setEnabled(b);
        dt_end.setEnabled(b);
    }
}
